using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Distributions;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Contents;
using NCS.Module.CMS.Library.Events;
using NCS.Module.CMS.Library.Zones;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class NewsInContentList1 : CMSWebControl
    {
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);

            //EventInfo info = EventController.GetInfo(eventid);
            ZoneInfo info = ZoneController.GetZone(catid);
            
            if(info != null)
            lblZoneName.Text = info.Zone_Name;

        ZoneInfo infoParent = ZoneController.GetZone(info.Zone_ParentID);
        hplParent.Text = infoParent.Zone_Name;
        hplParent.NavigateUrl = BuildUrlByZone(info.Zone_ParentID, 207);

            DataTable dtContents = DistributionController.GetDistributedContents_ByZone(catid, 10000);
            this.rpt_head.DataSource = dtContents;
            this.rpt_head.DataBind();            
        }

        protected void rpt_head_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataRowView row = (DataRowView)e.Item.DataItem;
            if (row != null)
            {
                int distid = ConvertUtility.ToInt32(row["Content_ID"]);
                string url =  BuildUrlByDistId(ConvertUtility.ToInt32(row["Distribution_ID"]), ConvertUtility.ToInt32(row["Distribution_ZoneID"]));                
               // string src = MultimediaUtility.GetListAvatar(ConvertUtility.ToString(row["Content_Avatar"]));
                string date = ConvertUtility.ToDateTime(row["Distribution_CreateDate"]).ToString("dd/MM/yyyy hh:mm:ss tt");

                string ava = MultimediaUtility.GetListAvatar(ConvertUtility.ToString(row["Content_Avatar"]));

                Literal ltt = (Literal)e.Item.FindControl("lttImg");
                if (!string.IsNullOrEmpty(ava) && System.IO.File.Exists(Server.MapPath(ava)))
                {
                    string alternate_text = MiscUtility.SafeHtmlToText(ConvertUtility.ToStringWithoutFontBold(row["Content_AvatarDescription"]));

                    string js_img = "javascript:window.location='" + url + "'";
                    ltt.Text = "<img src='" + ava + "' alt='" + alternate_text + "'   Width='150' onclick=\"" + js_img + "\"/>";
                }
                ltt.Text += "<a href='" + url + "' style='color:#062FAF;font-size:13px;'>";
                ltt.Text += NCS.Library.Utilities.ConvertUtility.ToString(row["Content_Headline"]);
                ltt.Text += "&nbsp;&nbsp;<span style='color:gray;font-size: 10px;'>";
                ltt.Text += date + "</span></a>";

                //Image img = (Image)e.Item.FindControl("img_img");
                //if (!string.IsNullOrEmpty(row["Content_Avatar"].ToString()) && System.IO.File.Exists(Server.MapPath(src)))
                //{
                //    img.ImageUrl = src;

                //    img.Attributes.Add("onclick", "javascript:window.location='" + url + "'");
                //    img.Attributes.Add("style", "cursor:hand; margin-right:5px;");
                //}
                //else
                //    img.Visible = false;

              
                //HyperLink link1 = (HyperLink)e.Item.FindControl("link1");
                //link1.Text = ConvertUtility.ToString(row["Content_Headline"]) + "&nbsp;&nbsp;<span style='color:gray;font-size: 10px;'>" + date + "</span>";
                //link1.NavigateUrl = url ;
            }
        }
    }
}